package com.villaday.idf.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Looper;
import android.provider.MediaStore;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.villaday.idf.AppContext;
import com.villaday.idf.R;
import com.villaday.idf.adapter2.CollectListAdapter2;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.AbsRecyclerViewAdapter.OnBtnListener;
import com.villaday.idf.base.BaseActivity;
import com.villaday.idf.base.BaseDialog;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.custom.LoadingDialog;
import com.villaday.idf.custom.LoadingSaveDialog;
import com.villaday.idf.custom.DividerItemDecoration.RVItemDecoration;
import com.villaday.idf.custom.YiJianTuiGuangDialog;
import com.villaday.idf.model.Collect;
import com.villaday.idf.model.Material_postersEntity202;
import com.villaday.idf.model.Member_collect_listEntity;
import com.villaday.idf.model.behaviorsEntity;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.LogeUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.ShareUtilse;
import com.villaday.idf.util.ToastUtil;
import com.villaday.idf.util.ToolBarUtil;
import com.villaday.idf.util.Utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import byc.imagewatcher.ImageWatcher;
import byc.imagewatcher.MessagePicturesLayout;
import me.bakumon.statuslayoutmanager.library.OnStatusChildClickListener;
import me.bakumon.statuslayoutmanager.library.StatusLayoutManager;
//我的收藏

public class MyCollectActivity extends BaseActivity implements OkHttpUtil.OnDataListener, SwipeRefreshLayout.OnRefreshListener, View.OnClickListener, OnAdapterCallbackListener, AbsRecyclerViewAdapter.OnItemClickListener, ImageWatcher.OnPictureLongPressListener, MessagePicturesLayout.Callback {

    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.srl)
    SwipeRefreshLayout srl;
    @BindView(R.id.toolbar_text)
    Toolbar toolbarText;

    private LoadingDialog loadingDialog;
    private Gson gson = new GsonBuilder().create();

    private int pageNo = 1;
    private int nextIndex = 1;
    private int pageSize = 3;
    List<Member_collect_listEntity.BodyBean.ListBean> data = new ArrayList();
    private CollectListAdapter2 collectListAdapter;

    private ImageWatcher vImageWatcher;
    private StatusLayoutManager statusLayoutManager;


    @Override
    protected int getViewResId() {
        return R.layout.activity_my_collect;
    }

    @Override
    protected void init() {

        statusLayoutManager = setupDefaultStatusLayoutManager(srl, new OnStatusChildClickListener() {
            @Override
            public void onEmptyChildClick(View view) {

            }

            @Override
            public void onErrorChildClick(View view) {
                loadData();
            }

            @Override
            public void onCustomerChildClick(View view) {

            }
        });
        ToolBarUtil.initToolBar(toolbarText, "我的收藏", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
        loadingDialog = LoadingDialog.newInstance("加载中");
        loadingDialog.show(getFragmentManager(), "loading");
        srl.setOnRefreshListener(this);

        rv.setLayoutManager(new LinearLayoutManager(this));
        collectListAdapter = new CollectListAdapter2(this, this, this);
        collectListAdapter.setPictureClickCallback(this);

        rv.setAdapter(collectListAdapter);

        rv.addItemDecoration(new RVItemDecoration(LinearLayout.VERTICAL, PhoneUtil.dp2px(this, 1), getResources().getColor(R.color.colorBg), PhoneUtil.dp2px(this, 1)));
        collectListAdapter.setOnItemClickListener(this);
       /* View inflate = View.inflate(getContext(), R.layout.recycle_head, null);
        homeListSaleAdapter.addHeaderView(inflate);*/

        collectListAdapter.setEmptyView2(R.layout.empty_order_tips, true, R.id.tv_perchase);
        collectListAdapter.setEmptyTips(R.id.tv_emptyTips, "您还没有心仪的素材");
        collectListAdapter.setEmptyTips(R.id.tv_perchase, "去找素材吧");
        collectListAdapter.setOnBtnListener(new OnBtnListener() {
            @Override
            public void function() {
                /*setResult(RESULT_OK);*/
                startActivity(new Intent(MyCollectActivity.this, DynamicActivity.class));

                onBackPressed();
            }
        });


    }

    @Override
    protected void loadData() {
        getData();
    }

    private void getData() {
        Map<String, String> map = new HashMap<>();
        map.put("pageNo", pageNo + "");
        map.put("pageSize", pageSize + "");
        OkHttpUtil.getJSON(this, Constant.URL.member_collect_list, map, this);
    }

    @Override
    public void onRefresh() {
        pageNo = 1;
        nextIndex = 1;
        getData();
    }

    //rv item 点击事件
    @Override
    public void onItemClick(View v, int position) {

       /* Intent intent = new Intent(this, HouseDetailsActivityFor3.class);
        intent.putExtra("type", 0);
        intent.putExtra("houseId", data.get(position).getHouse().getId());
        intent.putExtra("presellProduct", data.get(position).getModelType() == 52);

        intent.putExtra("brokerAge", data.get(position).getBrokerAge());
        intent.putExtra("persellId", data.get(position).getId());
        startActivity(intent);*/

    }

    @Override//rv 里面控件  喜欢和分享
    public void onClick(final View view) {
        switch (view.getId()) {
            case R.id.img_collect: {//收藏
                loadingDialog = LoadingDialog.newInstance("操作中");
                loadingDialog.show(this.getFragmentManager(), "loading");
                /*final behaviors behaviors = new behaviors(data.get((Integer) view.getTag()).isFavorite() ? 107 : 106
                        , new behaviors.ContextEntity(104, data.get((Integer) view.getTag()).getId()));
*/
                Collect collect = new Collect(!data.get((Integer) view.getTag()).isFavorite());
                Map<String, Object> map = new HashMap<>();
                OkHttpUtil.postJson(this, String.format(Constant.URL.member_collect, "54", data.get((Integer) view.getTag()).getId()), collect, map, new OkHttpUtil.OnDataListener() {
                    @Override
                    public void onResponse(String url, String json) {
                        dismissLoading();

                        LogeUtil.e("member_collect", json);
                        behaviorsEntity behaviorsEntity = gson.fromJson(json, com.villaday.idf.model.behaviorsEntity.class);

                        if (behaviorsEntity.getBody().getStatus() == 1) {


                            removeData((Integer) view.getTag());
                            ToastUtil.initToast(MyCollectActivity.this, "已取消收藏");

                        } else if (behaviorsEntity.getBody().getStatus() == 0) {
                            ToastUtil.initToast(MyCollectActivity.this, "取消失败");

                        } else {
                            ToastUtil.initToast(MyCollectActivity.this, "取消失败");

                        }

                    }

                    @Override
                    public void onFailure(String url, String error) {

                    }
                });
            }
            break;
            case R.id.tv_lookShop: {//查看商品

                switch (data.get((Integer) view.getTag()).getProductType()) {
                    case 0: {//无关联产品
                        break;
                    }
                    case 2: {//小区
                        Intent intent = new Intent(this, BourbonListActivity.class);
                        intent.putExtra("villageId", data.get((Integer) view.getTag()).getVillageid());
                        intent.putExtra("city", "");
                        intent.putExtra("area", "");

                        startActivity(intent);
                        break;
                    }
                    case 3: {//房源
                        Intent intent = new Intent(this, HouseDetailsActivityFor3.class);
                        intent.putExtra("type", 0);
                        intent.putExtra("houseId", data.get((Integer) view.getTag()).getHouse().getId());
                        intent.putExtra("presellProduct", false);

                        intent.putExtra("brokerAge", data.get((Integer) view.getTag()).getHouse().getBrokerAge());
                        intent.putExtra("persellId", data.get((Integer) view.getTag()).getPresellId());
                        startActivity(intent);
                        break;
                    }
                    case 52: {//特卖
                        Intent intent = new Intent(this, HouseDetailsActivityFor3.class);
                        intent.putExtra("type", 0);
                        intent.putExtra("houseId", data.get((Integer) view.getTag()).getHouse().getId());
                        intent.putExtra("presellProduct", true);

                        intent.putExtra("brokerAge", data.get((Integer) view.getTag()).getHouse().getBrokerAge());
                        intent.putExtra("persellId", data.get((Integer) view.getTag()).getPresellId());
                        startActivity(intent);
                        break;
                    }
                }


            }
            break;
            case R.id.tv_allFodder0: {//保存
                ClipboardManager mClipboardManager = mClipboardManager =
                        (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

                ClipData mClipData;

                mClipData = ClipData.newPlainText("test", data.get((Integer) view.getTag()).getAdWord());
                mClipboardManager.setPrimaryClip(mClipData);

                if (data.get((Integer) view.getTag()).getEnablePoster() == 0) {//1.动态列表 素材添加字段enablePoster(1:可以生成 0:无法生成),用来控制是否发送生成海报请求
                    List<String> picList = new ArrayList<>();
                    if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                        picList.add(data.get((Integer) view.getTag()).getPoster());


                    } else {
                        picList.addAll(data.get((Integer) view.getTag()).getPicList());

                    }
                    LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                    loadingDialog.show(getFragmentManager(), "0");
                    saveImageForRecursive(picList, picList.size(), loadingDialog);
                } else {
                    loadingDialog = LoadingDialog.newInstance("加载中");
                    loadingDialog.show(getFragmentManager(), "loading");
                    String materialId = data.get((Integer) view.getTag()).getId();
                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("modelType", data.get((Integer) view.getTag()).getModelType() + "");
                    OkHttpUtil.getJSON(this, String.format(Constant.URL.material_posters, materialId), hashMap, new OkHttpUtil.OnDataListener() {
                        @Override
                        public void onResponse(String url, String json) {
                            if (!TextUtils.isEmpty(json)) {
                                dismissLoading();
                                final Material_postersEntity202 material_postersEntity = gson.fromJson(json, Material_postersEntity202.class);
                                if ("200".equals(material_postersEntity.getCode())) {

                                    List<String> picList = new ArrayList<>();
                                    for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                        picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());

                                    }
                                    /*if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                        if (data.get((Integer) view.getTag()).getReplacePic() == 1) {
                                            picList.add(material_postersEntity.getBody().getPosterList().get(0).getUrl());

                                        } else {
                                            picList.add(data.get((Integer) view.getTag()).getPoster());

                                        }

                                    } else {

                                        if (data.get((Integer) view.getTag()).getReplacePic() == 1) {

                                           *//* if (data.get((Integer) view.getTag()).getPicList().size()+material_postersEntity.getBody().getPosterList().size()<=9){
                                                picList.addAll(data.get((Integer) view.getTag()).getPicList()) ;
                                                for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                    picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl()); ;
                                                }
                                            }else {

                                                for (int j = 0; j <9-material_postersEntity.getBody().getPosterList().size() ; j++) {
                                                    picList.add(data.get((Integer) view.getTag()).getPicList().get(j));
                                                }



                                                for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                    picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl()); ;
                                                }
                                            }*//*

                                            for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl()); ;
                                            }

                                        } else {
                                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                            if (data.get((Integer) view.getTag()).getPicList().size() < 9) {
                                                for (int j = 0; j < 9 - data.get((Integer) view.getTag()).getPicList().size(); j++) {
                                                  //  picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());
                                                    if (j<material_postersEntity.getBody().getPosterList().size()){
                                                        picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());

                                                    }
                                                }
                                            }


                                        }

                                    }*/
                                    LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                                    loadingDialog.show(getFragmentManager(), "0");
                                    saveImageForRecursive(picList, picList.size(), loadingDialog);


                                } else {
                                    ToastUtil.initToast(MyCollectActivity.this, material_postersEntity.getMsg());
                                }
                            }

                        }

                        @Override
                        public void onFailure(String url, String error) {

                        }
                    });
                }
                /*switch (data.get((Integer) view.getTag()).getProductType()) {
                    case 0: {//无关联产品
                        List<String> picList = new ArrayList<>();
                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                            picList.add(data.get((Integer) view.getTag()).getPoster());


                        } else {
                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                        }
                        LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                        loadingDialog.show(getFragmentManager(), "0");
                        saveImageForRecursive(picList, picList.size(), loadingDialog);

                        break;
                    }
                    case 2: {//小区
                        loadingDialog = LoadingDialog.newInstance("跳转中");
                        loadingDialog.show(getFragmentManager(), "loading");
                        String villageId = data.get((Integer) view.getTag()).getVillageid();

                        OkHttpUtil.getJSON(this, String.format(Constant.URL.vips_villages_posters, villageId), new OkHttpUtil.OnDataListener() {
                            @Override
                            public void onResponse(String url, String json) {
                                if (!TextUtils.isEmpty(json)) {
                                    dismissLoading();
                                    Material_postersEntity material_postersEntity = gson.fromJson(json, Material_postersEntity.class);
                                    if ("200".equals(material_postersEntity.getCode())) {
                                        LogeUtil.e("material_posters" + json);
                                        List<String> picList = new ArrayList<>();
                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                            picList.add(data.get((Integer) view.getTag()).getPoster());


                                        } else {
                                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                        }
                                        picList.add(material_postersEntity.getBody().getPoster());
                                        LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                                        loadingDialog.show(getFragmentManager(), "0");
                                        saveImageForRecursive(picList, picList.size(), loadingDialog);
                                    } else {
                                        ToastUtil.initToast(MyCollectActivity.this, material_postersEntity.getMsg());
                                    }
                                }

                            }

                            @Override
                            public void onFailure(String url, String error) {

                            }
                        });
                        break;
                    }
                    case 3: //房源
                    case 52: //特卖
                        loadingDialog = LoadingDialog.newInstance("加载中");
                        loadingDialog.show(getFragmentManager(), "loading");
                        String materialId = data.get((Integer) view.getTag()).getId();
                        HashMap<String, String> hashMap = new HashMap<>();
                        hashMap.put("modelType", data.get((Integer) view.getTag()).getModelType() + "");
                        OkHttpUtil.getJSON(this, String.format(Constant.URL.material_posters, materialId), hashMap, new OkHttpUtil.OnDataListener() {
                            @Override
                            public void onResponse(String url, String json) {
                                if (!TextUtils.isEmpty(json)) {
                                    dismissLoading();
                                    final Material_postersEntity material_postersEntity = gson.fromJson(json, Material_postersEntity.class);
                                    if ("200".equals(material_postersEntity.getCode())) {

                                        List<String> picList = new ArrayList<>();
                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                            picList.add(data.get((Integer) view.getTag()).getPoster());


                                        } else {
                                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                        }
                                        picList.add(material_postersEntity.getBody().getPoster());
                                        LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                                        loadingDialog.show(getFragmentManager(), "0");
                                        saveImageForRecursive(picList, picList.size(), loadingDialog);


                                    } else {
                                        ToastUtil.initToast(MyCollectActivity.this, material_postersEntity.getMsg());
                                    }
                                }

                            }

                            @Override
                            public void onFailure(String url, String error) {

                            }
                        });
                        break;
                }*/

            }
            break;
            case R.id.tv_allFodder1: {//全部素材

            }
            break;
            case R.id.tv_share0: {//一键发圈
                loadingDialog = LoadingDialog.newInstance("加载中");
                loadingDialog.show(getFragmentManager(), "loading");
                if (data.get((Integer) view.getTag()).getEnablePoster() == 0) {//1.动态列表 素材添加字段enablePoster(1:可以生成 0:无法生成),用来控制是否发送生成海报请求
                    dismissLoading();
                    ToastUtil.initToast(this, "分享文案已复制，去粘贴");

                    YiJianTuiGuangDialog yiJianTuiGuangDialog = YiJianTuiGuangDialog.newInstance(data.get((Integer) view.getTag()).getHouse().getBrokerAge());
                    yiJianTuiGuangDialog.show(getFragmentManager());
                    yiJianTuiGuangDialog.setOnItemClickListener(new BaseDialog.OnItemClickListener() {
                        @Override
                        public void onItemClick(View v) {
                            ClipboardManager mClipboardManager = mClipboardManager =
                                    (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

                            ClipData mClipData;

                            mClipData = ClipData.newPlainText("test", data.get((Integer) view.getTag()).getAdWord());
                            mClipboardManager.setPrimaryClip(mClipData);
                            switch (v.getId()) {
                                case R.id.tv_wx: {

                                    loadingDialog = LoadingDialog.newInstance("加载中");
                                    loadingDialog.show(getFragmentManager(), "loading");
                                    List<String> lists = new ArrayList<String>();
                                    if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                        lists.add(data.get((Integer) view.getTag()).getPoster());


                                    } else {
                                        lists.addAll(data.get((Integer) view.getTag()).getPicList());

                                    }
                                    ShareUtilse.shareImage(MyCollectActivity.this, 0, lists, lists.get(lists.size() - 1),"");

                                }

                                break;
                                case R.id.tv_pyq: {
                                    loadingDialog = LoadingDialog.newInstance("加载中");
                                    loadingDialog.show(getFragmentManager(), "loading");
                                    List<String> lists = new ArrayList<String>();
                                    if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                        lists.add(data.get((Integer) view.getTag()).getPoster());


                                    } else {
                                        lists.addAll(data.get((Integer) view.getTag()).getPicList());

                                    }
                                    ShareUtilse.shareImage(MyCollectActivity.this, 1, lists, lists.get(lists.size() - 1),data.get((Integer) view.getTag()).getAdWord());

                                }
                                break;
                                case R.id.tv_YJTG_save:
                                    List<String> picList = new ArrayList<>();
                                    if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                        picList.add(data.get((Integer) view.getTag()).getPoster());


                                    } else {
                                        picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                    }
                                    LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                                    loadingDialog.show(getFragmentManager(), "0");
                                    saveImageForRecursive(picList, picList.size(), loadingDialog);

                                    break;
                            }
                        }
                    });
                } else {
                    String materialId = data.get((Integer) view.getTag()).getId();
                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("modelType", data.get((Integer) view.getTag()).getModelType() + "");
                    OkHttpUtil.getJSON(this, String.format(Constant.URL.material_posters, materialId), hashMap, new OkHttpUtil.OnDataListener() {
                        @Override
                        public void onResponse(String url, String json) {
                            if (!TextUtils.isEmpty(json)) {
                                dismissLoading();
                                final Material_postersEntity202 material_postersEntity = gson.fromJson(json, Material_postersEntity202.class);
                                if ("200".equals(material_postersEntity.getCode())) {
                                    ToastUtil.initToast(MyCollectActivity.this, "分享文案已复制，去粘贴");
                                    ClipboardManager mClipboardManager = mClipboardManager =
                                            (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

                                    ClipData mClipData;

                                    mClipData = ClipData.newPlainText("test", data.get((Integer) view.getTag()).getAdWord());
                                    mClipboardManager.setPrimaryClip(mClipData);
                                    YiJianTuiGuangDialog yiJianTuiGuangDialog = YiJianTuiGuangDialog.newInstance(data.get((Integer) view.getTag()).getHouse().getBrokerAge());
                                    yiJianTuiGuangDialog.show(getFragmentManager());
                                    yiJianTuiGuangDialog.setOnItemClickListener(new BaseDialog.OnItemClickListener() {
                                        @Override
                                        public void onItemClick(View v) {

                                            switch (v.getId()) {
                                                case R.id.tv_wx: {


                                                    loadingDialog = LoadingDialog.newInstance("加载中");
                                                    loadingDialog.show(getFragmentManager(), "loading");
                                                    List<String> picList = new ArrayList<String>();
                                                    for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                        picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());

                                                    }
                                                    /*if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                                        if (data.get((Integer) view.getTag()).getReplacePic() == 1) {
                                                            picList.add(material_postersEntity.getBody().getPosterList().get(0).getUrl());

                                                        } else {
                                                            picList.add(data.get((Integer) view.getTag()).getPoster());

                                                        }

                                                    } else {

                                                        if (data.get((Integer) view.getTag()).getReplacePic() == 1) {

                                                            if (data.get((Integer) view.getTag()).getPicList().size()+material_postersEntity.getBody().getPosterList().size()<=9){
                                                                picList.addAll(data.get((Integer) view.getTag()).getPicList()) ;
                                                                for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                                    picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl()); ;
                                                                }
                                                            }else {

                                                                for (int j = 0; j <9-material_postersEntity.getBody().getPosterList().size() ; j++) {
                                                                    picList.add(data.get((Integer) view.getTag()).getPicList().get(j));
                                                                }



                                                                for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                                    picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl()); ;
                                                                }
                                                            }

                                                        } else {
                                                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                                            if (data.get((Integer) view.getTag()).getPicList().size() < 9) {
                                                                for (int j = 0; j < 9 - data.get((Integer) view.getTag()).getPicList().size(); j++) {
                                                                  //  picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());
                                                                    if (j<material_postersEntity.getBody().getPosterList().size()){
                                                                        picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());

                                                                    }
                                                                }
                                                            }


                                                        }

                                                    }*/
                                                    ShareUtilse.shareImage(MyCollectActivity.this, 0, picList, picList.get(picList.size() - 1),"");
                                                }

                                                break;
                                                case R.id.tv_pyq: {
                                                    loadingDialog = LoadingDialog.newInstance("加载中");
                                                    loadingDialog.show(getFragmentManager(), "loading");
                                                    List<String> picList = new ArrayList<String>();
                                                    for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                        picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());

                                                    }
                                                    /*if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                                        if (data.get((Integer) view.getTag()).getReplacePic() == 1) {
                                                            picList.add(material_postersEntity.getBody().getPosterList().get(0).getUrl());

                                                        } else {
                                                            picList.add(data.get((Integer) view.getTag()).getPoster());

                                                        }

                                                    } else {

                                                        if (data.get((Integer) view.getTag()).getReplacePic() == 1) {

                                                            if (data.get((Integer) view.getTag()).getPicList().size()+material_postersEntity.getBody().getPosterList().size()<=9){
                                                                picList.addAll(data.get((Integer) view.getTag()).getPicList()) ;
                                                                for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                                    picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl()); ;
                                                                }
                                                            }else {

                                                                for (int j = 0; j <9-material_postersEntity.getBody().getPosterList().size() ; j++) {
                                                                    picList.add(data.get((Integer) view.getTag()).getPicList().get(j));
                                                                }



                                                                for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                                    picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl()); ;
                                                                }
                                                            }

                                                        } else {
                                                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                                            if (data.get((Integer) view.getTag()).getPicList().size() < 9) {
                                                                for (int j = 0; j < 9 - data.get((Integer) view.getTag()).getPicList().size(); j++) {
                                                                    //picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());
                                                                    if (j<material_postersEntity.getBody().getPosterList().size()){
                                                                        picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());

                                                                    }
                                                                }
                                                            }


                                                        }

                                                    }*/
                                                    ShareUtilse.shareImage(MyCollectActivity.this, 1, picList, picList.get(picList.size() - 1),data.get((Integer) view.getTag()).getAdWord());
                                                }
                                                break;
                                                case R.id.tv_YJTG_save:
                                                    List<String> picList = new ArrayList<>();
                                                    for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                        picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());

                                                    }
                                                    /*if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                                        if (data.get((Integer) view.getTag()).getReplacePic() == 1) {
                                                            picList.add(material_postersEntity.getBody().getPosterList().get(0).getUrl());

                                                        } else {
                                                            picList.add(data.get((Integer) view.getTag()).getPoster());

                                                        }

                                                    } else {

                                                        if (data.get((Integer) view.getTag()).getReplacePic() == 1) {

                                                            if (data.get((Integer) view.getTag()).getPicList().size()+material_postersEntity.getBody().getPosterList().size()<=9){
                                                                picList.addAll(data.get((Integer) view.getTag()).getPicList()) ;
                                                                for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                                    picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl()); ;
                                                                }
                                                            }else {

                                                                for (int j = 0; j <9-material_postersEntity.getBody().getPosterList().size() ; j++) {
                                                                    picList.add(data.get((Integer) view.getTag()).getPicList().get(j));
                                                                }



                                                                for (int j = 0; j < material_postersEntity.getBody().getPosterList().size(); j++) {
                                                                    picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl()); ;
                                                                }
                                                            }

                                                        } else {
                                                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                                            if (data.get((Integer) view.getTag()).getPicList().size() < 9) {
                                                                for (int j = 0; j < 9 - data.get((Integer) view.getTag()).getPicList().size(); j++) {
                                                                    //picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());
                                                                    if (j<material_postersEntity.getBody().getPosterList().size()){
                                                                        picList.add(material_postersEntity.getBody().getPosterList().get(j).getUrl());

                                                                    }
                                                                }
                                                            }


                                                        }

                                                    }*/
                                                    LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                                                    loadingDialog.show(getFragmentManager(), "0");
                                                    saveImageForRecursive(picList, picList.size(), loadingDialog);
                                            }
                                        }
                                    });


                                } else {
                                    ToastUtil.initToast(MyCollectActivity.this, material_postersEntity.getMsg());
                                }
                            }

                        }

                        @Override
                        public void onFailure(String url, String error) {

                        }
                    });
                }

                /*switch (data.get((Integer) view.getTag()).getProductType()) {

                    case 0: {//无关联产品
                        dismissLoading();
                        YiJianTuiGuangDialog yiJianTuiGuangDialog = YiJianTuiGuangDialog.newInstance(data.get((Integer) view.getTag()).getHouse().getBrokerAge());
                        yiJianTuiGuangDialog.show(getFragmentManager());
                        yiJianTuiGuangDialog.setOnItemClickListener(new BaseDialog.OnItemClickListener() {
                            @Override
                            public void onItemClick(View v) {
                                ClipboardManager mClipboardManager = mClipboardManager =
                                        (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

                                ClipData mClipData;

                                mClipData = ClipData.newPlainText("test", data.get((Integer) view.getTag()).getAdWord());
                                mClipboardManager.setPrimaryClip(mClipData);
                                switch (v.getId()) {
                                    case R.id.tv_wx: {
                                        loadingDialog = LoadingDialog.newInstance("加载中");
                                        loadingDialog.show(getFragmentManager(), "loading");
                                        List<String> lists = new ArrayList<String>();
                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                            lists.add(data.get((Integer) view.getTag()).getPoster());


                                        } else {
                                            lists.addAll(data.get((Integer) view.getTag()).getPicList());

                                        }
                                        shareImage(0, lists);
                                    }

                                    break;
                                    case R.id.tv_pyq: {
                                        loadingDialog = LoadingDialog.newInstance("加载中");
                                        loadingDialog.show(getFragmentManager(), "loading");
                                        List<String> lists = new ArrayList<String>();
                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                            lists.add(data.get((Integer) view.getTag()).getPoster());


                                        } else {
                                            lists.addAll(data.get((Integer) view.getTag()).getPicList());

                                        }
                                        shareImage(1, lists);
                                    }
                                    break;
                                    case R.id.tv_YJTG_save:
                                        List<String> picList = new ArrayList<>();
                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                            picList.add(data.get((Integer) view.getTag()).getPoster());


                                        } else {
                                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                        }
                                        LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                                        loadingDialog.show(getFragmentManager(), "0");
                                        saveImageForRecursive(picList, picList.size(), loadingDialog);

                                        break;
                                }
                            }
                        });
                        break;
                    }
                    case 2: {//小区

                        String villageId = data.get((Integer) view.getTag()).getVillageid();

                        OkHttpUtil.getJSON(this, String.format(Constant.URL.vips_villages_posters, villageId), new OkHttpUtil.OnDataListener() {
                            @Override
                            public void onResponse(String url, String json) {
                                if (!TextUtils.isEmpty(json)) {
                                    dismissLoading();
                                    final Material_postersEntity material_postersEntity = gson.fromJson(json, Material_postersEntity.class);
                                    if ("200".equals(material_postersEntity.getCode())) {
                                        ToastUtil.initToast(MyCollectActivity.this, "分享文案已复制，去粘贴");

                                        YiJianTuiGuangDialog yiJianTuiGuangDialog = YiJianTuiGuangDialog.newInstance(data.get((Integer) view.getTag()).getHouse().getBrokerAge());
                                        yiJianTuiGuangDialog.show(getFragmentManager());
                                        yiJianTuiGuangDialog.setOnItemClickListener(new BaseDialog.OnItemClickListener() {
                                            @Override
                                            public void onItemClick(View v) {
                                                ClipboardManager mClipboardManager = mClipboardManager =
                                                        (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

                                                ClipData mClipData;

                                                mClipData = ClipData.newPlainText("test", data.get((Integer) view.getTag()).getAdWord());
                                                mClipboardManager.setPrimaryClip(mClipData);
                                                switch (v.getId()) {
                                                    case R.id.tv_wx: {

                                                        loadingDialog = LoadingDialog.newInstance("加载中");
                                                        loadingDialog.show(getFragmentManager(), "loading");
                                                        List<String> lists = new ArrayList<String>();
                                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                                            lists.add(data.get((Integer) view.getTag()).getPoster());


                                                        } else {
                                                            lists.addAll(data.get((Integer) view.getTag()).getPicList());

                                                        }
                                                        lists.add(material_postersEntity.getBody().getPoster());
                                                        shareImage(0, lists);
                                                    }

                                                    break;
                                                    case R.id.tv_pyq: {
                                                        loadingDialog = LoadingDialog.newInstance("加载中");
                                                        loadingDialog.show(getFragmentManager(), "loading");
                                                        List<String> lists = new ArrayList<String>();
                                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                                            lists.add(data.get((Integer) view.getTag()).getPoster());


                                                        } else {
                                                            lists.addAll(data.get((Integer) view.getTag()).getPicList());

                                                        }
                                                        lists.add(material_postersEntity.getBody().getPoster());
                                                        shareImage(1, lists);
                                                    }
                                                    break;
                                                    case R.id.tv_YJTG_save:
                                                        List<String> picList = new ArrayList<>();
                                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                                            picList.add(data.get((Integer) view.getTag()).getPoster());


                                                        } else {
                                                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                                        }
                                                        picList.add(material_postersEntity.getBody().getPoster());
                                                        LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                                                        loadingDialog.show(getFragmentManager(), "0");
                                                        saveImageForRecursive(picList, picList.size(), loadingDialog);
                                                }
                                            }
                                        });


                                    } else {
                                        ToastUtil.initToast(MyCollectActivity.this, material_postersEntity.getMsg());
                                    }
                                }

                            }

                            @Override
                            public void onFailure(String url, String error) {

                            }
                        });

                        break;
                    }
                    case 3://房源
                    case 52:  //特卖

                        String materialId = data.get((Integer) view.getTag()).getId();
                        HashMap<String, String> hashMap = new HashMap<>();
                        hashMap.put("modelType", data.get((Integer) view.getTag()).getModelType() + "");
                        OkHttpUtil.getJSON(this, String.format(Constant.URL.material_posters, materialId), hashMap, new OkHttpUtil.OnDataListener() {
                            @Override
                            public void onResponse(String url, String json) {
                                if (!TextUtils.isEmpty(json)) {
                                    dismissLoading();
                                    final Material_postersEntity material_postersEntity = gson.fromJson(json, Material_postersEntity.class);
                                    if ("200".equals(material_postersEntity.getCode())) {
                                        ToastUtil.initToast(MyCollectActivity.this, "分享文案已复制，去粘贴");

                                        YiJianTuiGuangDialog yiJianTuiGuangDialog = YiJianTuiGuangDialog.newInstance(data.get((Integer) view.getTag()).getHouse().getBrokerAge());
                                        yiJianTuiGuangDialog.show(getFragmentManager());
                                        yiJianTuiGuangDialog.setOnItemClickListener(new BaseDialog.OnItemClickListener() {
                                            @Override
                                            public void onItemClick(View v) {
                                                ClipboardManager mClipboardManager = mClipboardManager =
                                                        (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

                                                ClipData mClipData;

                                                mClipData = ClipData.newPlainText("test", data.get((Integer) view.getTag()).getAdWord());
                                                mClipboardManager.setPrimaryClip(mClipData);
                                                switch (v.getId()) {
                                                    case R.id.tv_wx: {

                                                        loadingDialog = LoadingDialog.newInstance("加载中");
                                                        loadingDialog.show(getFragmentManager(), "loading");
                                                        List<String> lists = new ArrayList<String>();
                                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                                            lists.add(data.get((Integer) view.getTag()).getPoster());


                                                        } else {
                                                            lists.addAll(data.get((Integer) view.getTag()).getPicList());

                                                        }
                                                        lists.add(material_postersEntity.getBody().getPoster());
                                                        shareImage(0, lists);
                                                    }

                                                    break;
                                                    case R.id.tv_pyq: {
                                                        loadingDialog = LoadingDialog.newInstance("加载中");
                                                        loadingDialog.show(getFragmentManager(), "loading");
                                                        List<String> lists = new ArrayList<String>();
                                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                                            lists.add(data.get((Integer) view.getTag()).getPoster());


                                                        } else {
                                                            lists.addAll(data.get((Integer) view.getTag()).getPicList());

                                                        }
                                                        lists.add(material_postersEntity.getBody().getPoster());
                                                        shareImage(1, lists);
                                                    }
                                                    break;
                                                    case R.id.tv_YJTG_save:
                                                        List<String> picList = new ArrayList<>();
                                                        if (data.get((Integer) view.getTag()).getMaterialType() == 1) {//为海报
                                                            picList.add(data.get((Integer) view.getTag()).getPoster());


                                                        } else {
                                                            picList.addAll(data.get((Integer) view.getTag()).getPicList());

                                                        }
                                                        picList.add(material_postersEntity.getBody().getPoster());
                                                        LoadingSaveDialog loadingDialog = LoadingSaveDialog.newInstance("已保存" + (1) + "/" + picList.size() + "张");
                                                        loadingDialog.show(getFragmentManager(), "0");
                                                        saveImageForRecursive(picList, picList.size(), loadingDialog);
                                                }
                                            }
                                        });


                                    } else {
                                        ToastUtil.initToast(MyCollectActivity.this, material_postersEntity.getMsg());
                                    }
                                }

                            }

                            @Override
                            public void onFailure(String url, String error) {

                            }
                        });
                        break;

                }*/
            }
            break;
            case R.id.tv_share1: {//一键发圈

            }
            break;
            case R.id.tv_share2: {//一键发圈

            }
            break;
        }

    }

    public void saveImageForRecursive(final List<String> img, final int imgSize, final LoadingSaveDialog loadingSaveDialog) {//递归保存
        if (loadingSaveDialog != null) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    loadingSaveDialog.setLoadingTips("已保存" + (imgSize - img.size() + 1) + "/" + imgSize + "张");
                }
            });

        }
        if (img.size() != 0) {

            new Thread(new Runnable() {
                @Override
                public void run() {
                    saveImageToSdCard(MyCollectActivity.this, img.get(0), true);

                    img.remove(0);
                    saveImageForRecursive(img, imgSize, loadingSaveDialog);
                }
            }
            ).start();
        } else {

            if (loadingSaveDialog != null) {

                loadingSaveDialog.dismiss();
            }
            Looper.prepare();
            String fileName;
            if (Build.BRAND.equals("Xiaomi")) { // 小米手机
                fileName = "/DCIM/Camera/";
            } else {  // Meizu 、Oppo
                fileName = "/DCIM/Camera/";
            }
            ToastUtil.initToast(this, "图文保存至" + fileName);

            ToastUtil.initToast(this, "图文保存成功！快去发朋友圈推广吧~");
            Looper.loop();
        }

    }


    public static String IMAGE_NAME = "iv_share_";
    public static int i = 0;

    //根据网络图片url路径保存到本地
    public final File saveImageToSdCard(Context context, String image, boolean isxiangce) {
        boolean success = false;
        File file = null;
        try {
            if (isxiangce) {
                file = createXiangCeImageFile(context);
            } else {
                file = createStableImageFile(context);

            }

            Bitmap bitmap = null;
            URL url = new URL(image);
            HttpURLConnection conn = null;
            conn = (HttpURLConnection) url.openConnection();
            InputStream is = null;
            is = conn.getInputStream();
            bitmap = BitmapFactory.decodeStream(is);

            FileOutputStream outStream;

            outStream = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
            outStream.flush();
            outStream.close();
            success = true;
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
            values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            Uri uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

            context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getAbsolutePath())));//path_export是你导出的文件路径
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (success) {
            return file;
        } else {
            return null;
        }
    }

    //创建相册
    public static File createXiangCeImageFile(Context context) throws IOException {
        String imageFileName = IMAGE_NAME + System.currentTimeMillis() + ".jpg";

        String fileName;
        File file;
        if (Build.BRAND.equals("Xiaomi")) { // 小米手机
            fileName = Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/" + imageFileName;
        } else {  // Meizu 、Oppo
            fileName = Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/" + imageFileName;
        }
        file = new File(fileName);

        if (file.exists()) {
            file.delete();
        }
        return file;
    }

    //创建本地保存路径
    public static File createStableImageFile(Context context) throws IOException {

        i++;
        String imageFileName = IMAGE_NAME + System.currentTimeMillis() + ".jpg";
        File storageDir = context.getExternalCacheDir();
        File image = new File(storageDir, imageFileName);
        return image;
    }

    @Override
    public void onCallback() {
        if (nextIndex == pageNo + 1) {
            pageNo++;
            getData();
        }
    }

    @Override
    public void onResponse(String url, String json) {
        if (statusLayoutManager != null) {

            statusLayoutManager.showSuccessLayout();
        }
        if (Constant.URL.member_collect_list.equals(url)) {
            LogeUtil.e("member_collect_list", json);
            dismissLoading();
            Member_collect_listEntity materialRecommendEntity = gson.fromJson(json, Member_collect_listEntity.class);

            removeLoadingItem();
            if (pageNo == 1) {
                data.clear();
            }

            if ("200".equals(materialRecommendEntity.getCode())) {
                   /* if (pageNo == 1 && presellEntity.getBody().getRecomendList() != null && presellEntity.getBody().getRecomendList().getList() != null) {

                        dataHead.addAll(presellEntity.getBody().getRecomendList().getList());
                        homeListSaleHeadAdapter.setData(dataHead);
                    }*/
                boolean isTranslucentStatus = false;

                data.addAll(materialRecommendEntity.getBody().getList());

                // 一般来讲， ImageWatcher 需要占据全屏的位置
// 如果是透明状态栏，你需要给ImageWatcher标记 一个偏移值，以修正点击ImageView查看的启动动画的Y轴起点的不正确
// 配置error图标 如果不介意使用lib自带的图标，并不一定要调用这个API
//设置指示器（默认小白点）
//设置指示器颜色
// 长按图片的回调，你可以显示一个框继续提供一些复制，发送等功能
//调用show方法前，请先调用setLoader 给ImageWatcher提供加载图片的实现
                vImageWatcher = ImageWatcher.Helper.with(this) // 一般来讲， ImageWatcher 需要占据全屏的位置
                        .setTranslucentStatus(!isTranslucentStatus ? Utils.calcStatusBarHeight(this) : 0) // 如果是透明状态栏，你需要给ImageWatcher标记 一个偏移值，以修正点击ImageView查看的启动动画的Y轴起点的不正确
                        .setErrorImageRes(R.mipmap.error_picture) // 配置error图标 如果不介意使用lib自带的图标，并不一定要调用这个API
                        .setHintMode(ImageWatcher.POINT)//设置指示器（默认小白点）
                        .setHintColor(getResources().getColor(R.color.colorRed), getResources().getColor(R.color.colorWhite))//设置指示器颜色
                        .setOnPictureLongPressListener(this) // 长按图片的回调，你可以显示一个框继续提供一些复制，发送等功能
                        .setLoader(new ImageWatcher.Loader() {//调用show方法前，请先调用setLoader 给ImageWatcher提供加载图片的实现
                            @Override
                            public void load(Context context, String url, final ImageWatcher.LoadCallback lc) {
                                Glide.with(context).asBitmap().load(url).into(new SimpleTarget<Bitmap>() {
                                    @Override
                                    public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                                        lc.onResourceReady(resource);
                                    }

                                    @Override
                                    public void onLoadStarted(Drawable placeholder) {
                                        lc.onLoadStarted(placeholder);
                                    }

                                    @Override
                                    public void onLoadFailed(Drawable errorDrawable) {
                                        lc.onLoadFailed(errorDrawable);
                                    }
                                });
                            }
                        })
                        .create();

                if (materialRecommendEntity.getBody().isHasNext()) {
                    data.add(new Member_collect_listEntity.BodyBean.ListBean(1));
                    nextIndex = pageNo + 1;

                } else {
                    addBaseLine();
                }

            } else {
                addBaseLine();
            }
            collectListAdapter.setData(data);
        }
    }

    @Override
    public void onFailure(String url, String error) {
        dismissLoading();
        if (statusLayoutManager != null) {

            statusLayoutManager.showErrorLayout();
        }
    }

    private void dismissLoading() {

        if (srl != null && srl.isRefreshing()) {
            srl.setRefreshing(false);
        }
        if (loadingDialog != null) {
            loadingDialog.dismiss();
        }
    }

    private void removeLoadingItem() {
        if (data.size() > 0) {
            if (data.get(data.size() - 1).getMyType() == 1) {
                data.remove(data.size() - 1);
            }
        }
    }

    private void addBaseLine() {
        if (pageNo != 1) {
            data.add(new Member_collect_listEntity.BodyBean.ListBean(2));
        }
    }

    //  删除数据
    public void removeData(int position) {
        AppContext.isLikeChange = true;

        data.remove(position);
        collectListAdapter.notifyItemRemoved(position);
        collectListAdapter.notifyDataSetChanged();

        if (data.size() == 1 && nextIndex > 1) {
            data.remove(0);
            collectListAdapter.notifyItemRemoved(0);

        }

        //删除动画
        collectListAdapter.notifyDataSetChanged();
    }


    @Override
    public void onPictureLongPress(ImageView v, String url, int pos) {

    }

    public boolean onBack() {
        if (vImageWatcher == null) {
            return false;
        } else {
            // 当确认没有子Fragmnt时可以直接return false
            if (!vImageWatcher.handleBackPressed()) {
                return BackHandlerHelper.handleBackPress(this);
            } else {
                return !BackHandlerHelper.handleBackPress(this);
            }
        }


    }

    @Override
    public void onBackPressed() {

        if (!onBack()) {
            super.onBackPressed();

        }
    }

    @Override
    public void onThumbPictureClick(ImageView i, List<ImageView> imageGroupList, List<String> urlList) {
        vImageWatcher.show(i, imageGroupList, urlList);

    }

    @Override
    public void onResume() {
        super.onResume();
        dismissLoading();
    }
}

